<template>
  <CDrawer v-model:visible="drawerVisible" :title="`回收站${recycleCount}`">
    <template #headerOp>
      <el-button
        type="primary"
        @click="handleClear"
        :disabled="!recycleList.length"
        v-btnPermission="'PCF_COMPLETE_MODEL_DELETE'"
      >
        <template #icon>
          <CIcon type="c-xian-qingkong" class="jinggao-icon-style"></CIcon>
        </template>
        清空回收站</el-button
      >
    </template>
    <el-scrollbar
      ref="scrollRef"
      height="calc(100vh - 60px)"
      @scroll="scroll"
      v-if="recycleList.length"
    >
      <div class="recycle-cell" v-for="(item, index) in recycleList" :key="index">
        <div class="recycle-cell-content">
          <div class="recycle-cell-left">
            <div class="g-flex">
              <span class="tag">{{ item.accountYear }}年</span>
              <p class="g-font-14n1" v-ellTooltip>{{ item.modelName }}</p>
            </div>
            <div class="g-mt2 g-flex">
              <p class="g-font-12n3 g-mr4" v-ellTooltip>{{ item.recyclePerson }}</p>
              <p class="g-font-12n3 g-flex-shrink-0">删除于 {{ item.recycleTime }}</p>
            </div>
          </div>
          <div class="recycle-cell-right">
            <CIconButton
              icon="c-xian-chehui"
              content="恢复模型"
              v-if="hasBtnPermission('PCF_RESTORE_MODEL')"
              @click="handleReset(item)"
            ></CIconButton>
            <CIconButton
              icon="c-xian-shanchu"
              content="彻底删除"
              v-if="hasBtnPermission('PCF_COMPLETE_MODEL_DELETE')"
              @click="handleDel(item)"
            ></CIconButton>
          </div>
        </div>
        <el-divider />
      </div>
    </el-scrollbar>
    <div class="cell-empty" v-else>
      <img src="@/assets/images/icon_notice_null.png" class="img" />
      <p class="g-font-14n3-2">暂无消息</p>
    </div>
  </CDrawer>
</template>
<script lang="ts" setup>
import { computed, defineProps, defineEmits, watch } from 'vue';
import { CDrawer } from '@/components/CDrawer/index';
import { useDetail } from './useDetail';
import { hasBtnPermission } from '@/directives/btnPermission';
interface IDrawerProps {
  visible: boolean;
}

const props = defineProps<IDrawerProps>();
const emits = defineEmits(['update:visible', 'refresh']);

const { recycleList, scroll, scrollRef, handleClear, handleDel, handleReset, recycleCount, init } =
  useDetail(emits);
const drawerVisible = computed({
  get: () => {
    return props.visible;
  },
  set: (value: boolean) => {
    emits('update:visible', value);
  }
});
watch(
  () => drawerVisible.value,
  val => {
    if (val) {
      init();
    }
  }
);
</script>
<style lang="scss" scoped>
.cell-empty {
  height: 386px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .img {
    width: 62px;
    height: 41px;
    margin: 167px 0 19px;
  }
}
.recycle-cell {
  width: 100%;
  height: 80px;
  background: #ffffff;
  padding: 0 20px 0 24px;
  :deep(.el-divider--horizontal) {
    margin: 0;
  }
  .recycle-cell-content {
    height: 79px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .recycle-cell-left {
      width: 263px;
      .tag {
        width: 53px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        background: #edf2f7;
        border-radius: 2px;
        font-size: 12px;
        color: #028968;
        margin-right: 4px;
      }
    }
    .recycle-cell-right {
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}
</style>
